package com.jic.interaction.ChinaPost.service.impl;

import com.jic.interaction.common.utils.HttpClientUtil;
import com.jic.interaction.ChinaPost.model.vo.request.DamageRecallRequest;
import com.jic.interaction.ChinaPost.service.DamageRecallService;
import com.jic.interaction.ChinaPost.sever.GetSign;
import com.jic.interaction.ChinaPost.sever.NonceService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
@Service
public class DamageRecallServiceImpl implements DamageRecallService {

    @Value("${route.value}")
    private String url;
    @Resource
    NonceService nonceService;
    @Resource
    GetSign getSign;

    @Override
    public String damageRecall(DamageRecallRequest request) throws InterruptedException, ExecutionException, IOException {
       //测试
        String url =this.url+ "/m/dbs-front/compensationPay/revoke";
        //线上
        //String url =this.url+ "/dbs-front/compensationPay/revoke";
        //必输校验
        Map map = new HashMap();
        map.put("appId",request.getAppId());
        map.put("userId",request.getUserId());
        map.put("orderNo",request.getOrderNo());
        map.put("orgOrderNo",request.getOrgOrderNo());
        map.put("txnTime",request.getTxnTime());

        JSONObject jsonObject = JSONObject.fromObject(request);
        String str = HttpClientUtil.requestPath(url, map,jsonObject.toString());
        return  str;
    }

    @Override
    public String damageRefund(DamageRecallRequest request) throws InterruptedException, ExecutionException, IOException {
        //测试
        String url = this.url+"/m/dbs-front/compensationPay/refund";
        //线上
       //String url = this.url+"/dbs-front/compensationPay/refund";
        //必输校验
        Map map = new HashMap();
        map.put("appId",request.getAppId());
        map.put("userId",request.getUserId());
        map.put("orderNo",request.getOrderNo());
        map.put("orgOrderNo",request.getOrgOrderNo());
        map.put("txnTime",request.getTxnTime());
        map.put("Refund_amount",request.getRefund_amount());

        JSONObject jsonObject = JSONObject.fromObject(request);
        String str = HttpClientUtil.requestPath(url, map,jsonObject.toString());
        return  str;
    }



}
